import {MyHttp} from '../../services/myHttp/myhttp.service';
import { Injectable}  from '@angular/core';
import { Score} from '../../services/model/score';
@Injectable()
export class MyScoresService{
  constructor(private http:MyHttp){

  }

  query(body:any):Promise<{count:number,items:Score[]}>{
    return this.http.post({
      api:this.http.api.queryOwnScore,
      body:body
    }).toPromise()
      .then((res)=> {
        if (res.status === 200) {
          let result=res.json();
          console.log(result);
          if(result.status){
            let items=result.data.items;
            let count=result.data.count;
            let scores=[];
            for(let o in items){
              let item=new Score();
              item.scoreId=items[o].scoreId;
              item.score=items[o].score;
              item.studentId=items[o].studentId;
              item.studentName=items[o].studentName;
              item.courseId=items[o].courseId;
              item.courseName=items[o].courseName;
              item.majorId=items[o].majorId;
              item.major=items[o].major;
              item.gradeId=items[o].gradeId;
              item.gradeName=items[o].gradeName;
              scores.push(item);
            }
            console.log(scores);
            return Promise.resolve({count:count,items:scores});
          }
        }

      });
  }
}

